<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class ApprovesLeave extends Model
{
    // 表名
    protected $table = 'approves_leave';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        'leave_time_text',
        'leave_type_text'
    ];

    public function getLeaveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['leave_time']) ? $data['leave_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getLeaveTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['leave_type']) ? $data['leave_type'] : '');
        if (!$value){
            return '';
        }
        $type = LeaveType::where('id',$value)->find();
        return !$type ? '' : $type['name'];
    }


}
